package lembrete.core.backbeans;

import java.io.IOException;

import javax.faces.context.FacesContext;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

import lembrete.core.beans.Usuario;

public class LoginFilter implements Filter {

	public LoginFilter(){
		//
	}
	
	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		Usuario usuario = null; 
		try {
			usuario = (Usuario)FacesContext.getCurrentInstance().
											getExternalContext().getSessionMap().get("user");
		} catch (Exception e) {
			//never do that!
		}
		/*
		if(usuario == null){
			HttpServletResponse res = (HttpServletResponse) response;
			res.sendRedirect("/Lembrete/erro_login.jsf");
		}else{
			chain.doFilter(request, response);
		}*/
		
	}

	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		
	}

}
